﻿using BCCommon;
using BCDto.WeChatComponent.WeChatUser;
using BCService.WeChatComponent.WeChatUserRelevantService;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BCTMSRESTful.Controllers.Management.WeChat
{
    /// <summary>
    /// 微信用户标签控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class WeChatUserInfoController : ManagementBaseController
    {
        private readonly IWeChatUserRelevantService weChatUserRelevantService;

        public WeChatUserInfoController(IWeChatUserRelevantService weChatUserRelevantService)
        {
            this.weChatUserRelevantService = weChatUserRelevantService;
        }

        /// <summary>
        /// 添加微信用户备注名称。
        /// </summary>
        /// <param name="openid">微信用户OpenId</param>
        /// <param name="remark">微信用户备注名称</param>
        /// <response code="200">设置微信用户备注名称成功。</response>
        /// <returns></returns>
        [HttpPut("[action]/{openid}")]
        [ProducesResponseType(typeof(void), 200)]
        public IActionResult Remark([FromRoute(Name ="openid")]string openid,
            [FromQuery(Name = "remark")]string remark)
        {
            this.weChatUserRelevantService.UpdateRemark(openid, remark);
            return this.Ok(true);
        }

        /// <summary>
        /// 获取微信用户信息列表(带分页)。
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="tagId">标签Id</param>
        /// <param name="subscribeScene">关注渠道</param>
        /// <param name="remark">微信用户备注名</param>
        /// <param name="phone">用户手机</param>
        /// <param name="country">微信用户国家</param>
        /// <param name="province">微信用户省份</param>
        /// <param name="city">微信用户城市</param>
        /// <param name="role">用户角色</param>
        /// <param name="ascending">排序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">每页数据条数</param>
        /// <response code="200">微信用户信息列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WeChatUserInfoDto>), 200)]
        public IActionResult Query([FromQuery(Name = "name")]string name,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "tag_id")]int? tagId,
            [FromQuery(Name = "subscribe_scene")]string subscribeScene,
            [FromQuery(Name = "remark")]string remark,
            [FromQuery(Name = "phone")]string phone,
            [FromQuery(Name = "country")]string country,
            [FromQuery(Name = "province")]string province,
            [FromQuery(Name = "city")]string city,
            [FromQuery(Name = "role")]string role,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return this.Ok(this.weChatUserRelevantService.Get(name, start, end,tagId,subscribeScene,remark,phone,country,province,city,role, ascending, index, size));
        }
        /// <summary>
        /// 同步微信用户OpenId
        /// </summary>
        /// <response code="200"></response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult SynchronizeUserOpenId()
        {
            this.weChatUserRelevantService.SynchronizeUserOpenId();
            return this.Ok(true);
        }
        /// <summary>
        /// 同步微信用户信息
        /// </summary>
        /// <response code="200"></response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult SynchronizeUserInfo()
        {
            this.weChatUserRelevantService.SynchronizeUserInfo();
            return this.Ok(true);
        }
    }
}
